import apis from '../../http/apis/apis'
export default {
    namespaced: true,
    state: {
        nowLessors: {
            username: '',
            _id: ''
        },
        tableData: [
        ],
        currentPage: 1,
        pageSize: 5,
        total: 0,
        pages: 0,
    },
    mutations: {
        setNowLessors(state, { username, _id }) {
            state.nowLessors.username = username,
                state.nowLessors._id = _id
        },
        getlessors(state, data) {
            state.tableData = data.tableData,
                state.total = data.total,
                state.pages = data.pages
        },
        //改变每页显示条数
        changePageSize(state, pageSize) {
            state.pageSize = pageSize
        },
        //改变当前页
        changecurrentPage(state, currentPage) {
            state.currentPage = currentPage
        },
    },
    actions: {
        async register(context, newLessors) {
            const { data } = await apis.lessors.register(newLessors)
            if (data.status) {
                return data
            }
        },
        async checkUsername(context, username) {
            const { data } = await apis.lessors.checkUsername(username)
            return data
        },

        //出租方查看个人的订单
        async getLessorsOrders(context, id) {
            const { data } = await apis.lessors.getLessorsOrders(id)
            return data

        },
        async login(context, username) {
            const { data } = await apis.lessors.login(username)
            return data
        },
        //

        //审核出租方渲染列表
        async getLessors(context, input) {
            const { data } = await apis.lessors.getLessors({
                searchType: input.input1,
                searchValue: input.input2,
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize
            });
            if (data.status) {
                context.commit('getlessors', data.data)
            }
        },
        //改变状态
        async getState(context, a) {
            if (a.state == 1) {
                a.state = 2
            } else if (a.state == 2) {
                a.state = 1
            }
            const { data } = await apis.lessors.getState({
                _id: a._id,
                state: a.state
            });
            return data
        },

    },

}
